﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using DAL;
using System.Collections.Generic;

public partial class PrintBaiviet : System.Web.UI.Page
{
    BAIVIETBLL bvBll = new BAIVIETBLL();
    THANHVIENBLL tvBll = new THANHVIENBLL();
    SINHHIEUBLL shBll = new SINHHIEUBLL();
    TIENCANBLL tcBll = new TIENCANBLL();
    THONGTINKHACBLL ttkBll = new THONGTINKHACBLL();
    TRIEUCHUNGBLL tchBll = new TRIEUCHUNGBLL();
    CANLAMSANGBLL clsBll = new CANLAMSANGBLL();
    XETNGHIEMBLL xnBll = new XETNGHIEMBLL();
    LOAICLSBLL lclsBll = new LOAICLSBLL();
    HOSOBENHANBLL hsbaBll = new HOSOBENHANBLL();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["tenthanhvien"] == null) Response.Redirect("LogIn.aspx");
        if (!Page.IsPostBack) {

            if (Page.Request["mabv"] != null)
            {
                showAll();
            }
        }
    }

    private void showAll(){
        
        int mabv =Int32.Parse( Page.Request["mabv"]);
        BAIVIET bv = bvBll.getBaivietWithIDBaiviet(mabv);
        HOSOBENHAN hsba = hsbaBll.getHosobenhanWithIdBaiviet(bv.mabaiviet);

        lb_tenbai.Text = bv.tenbaiviet;
        lb_ngaylap.Text = bv.ngaylap.ToString();

        THANHVIEN tv = tvBll.getThanhvienWithIDBaiviet(bv.mabaiviet);

        lb_tvvb.Text = tv.tenthanhvien;
        lb_chucvu.Text = tv.chucvu;

        //noi dung
        lb_noidung.Text = bv.noidung;

        //sinh hieu
        SINHHIEU sh = shBll.getSinhhieuWithIdBaiviet(bv.mabaiviet);
        lb_time_sh.Text = sh.ngaytao.ToString();
        lb_nhiptho.Text = sh.nhiptho;
        lb_nhietdo.Text = sh.nhietdo;
        lb_huyetap.Text = sh.huyetap;
        lb_mach.Text = sh.mach;

        //tien can
        TIENCAN tc = tcBll.getTiencanWithIDBaiviet(bv.mabaiviet);
        lb_tiencan.Text = tc.tiencan;
        lb_tiencan_time.Text = tc.ngaytao.ToString();

        //trieuchung
        TRIEUCHUNG tch = tchBll.getTrieuchungWithIDBaiviet(bv.mabaiviet);
        lb_trieuchung.Text = tch.trieuchung;
        lb_trieuchung_time.Text = tch.ngaytao.ToString();

        //thong tin kjac
        THONGTINKHAC ttk = ttkBll.getThongtinkhacWithIDBaiviet(bv.mabaiviet);
        lb_ttk.Text = ttk.noidung;
        lb_ttk_time.Text = ttk.ngaytao.ToString();

        //canlamsang
        string str_inner_cls = "<ol>";
        List<LOAICLS> listCLs = lclsBll.getAll();
        foreach (LOAICLS lcls in listCLs) {
            str_inner_cls += "<li>";
            str_inner_cls += "<b>" + lcls.tenloai + ": </b>";
            CANLAMSANG cls = clsBll.getCanlamsangWithIDMabaAndIDLoaiCLS(hsba.mabenhan, lcls.maloaicls);
            str_inner_cls += cls.ketquacls;

            str_inner_cls += "</li>";      
        }
        str_inner_cls += "</ol>";
        div_canlamsang.InnerHtml = str_inner_cls;

        //xet nghiem
        string inner = "";
        List<XETNGHIEM> listXn = xnBll.getXetnghiemWithIdBaiviet(Int32.Parse(Page.Request["mabv"]));

        foreach (XETNGHIEM xn in listXn)
        {
            inner += "<br/>";
            inner += "<b style=\"color:Green;\">" + xn.tenxetnghiem + "</b>" + "(" + xn.ngaytao.ToLongDateString() + " - " + xn.ngaytao.ToLongTimeString() + " )";

            inner += "<br/>";
            inner += "<br/>";
            inner += "<ul>";
            List<XNDataShow> listXnShow = xnBll.getDanhmucxetnghiemChossedWithIDXetnghiem(xn.maxetnghiem);

            foreach (XNDataShow xnShow in listXnShow)
            {
                inner += ("<li><b>" + xnShow.tendanhmuc + " :</b> " + xnShow.ketqua + "</li>");
            }
            inner += "</ul>";
            inner += "<br/>";
        }

        if (listXn.Count == 0) div_xetnghiem.InnerHtml = "<b>Chưa có nội dung</b>";
        else div_xetnghiem.InnerHtml = inner;

        //ketluan
        lb_ketluan.Text = hsba.ketluan;
    }
}
